package com.woniuxy.security.util;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Date;
import java.util.Map;

/**
 * Date: 2021/6/29:20:12  <br/>
 * Description:
 */
public class JwtUtil {
    public static String createToken(Map claims, PrivateKey privateKey){
        return Jwts.builder()
                .setClaims(claims)
                .setHeaderParam("typ","JWT")
                .setIssuedAt(new Date())
                .signWith(privateKey, SignatureAlgorithm.RS256)
                .compact();
    }

    public static Map parseToken(String token , PublicKey publicKey){
        return Jwts.parserBuilder()
                .setSigningKey(publicKey)
                .build().parseClaimsJws(token)
                .getBody();
    }
}
